<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
    <title>用户管理</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#no").focus();
            $("#inputForm").validate({
                rules: {
                    loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${user.loginName}')}
                },
                messages: {
                    loginName: {remote: "用户登录名已存在"},
                    confirmNewPassword: {equalTo: "输入与上面相同的密码"}
                },
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
        });
    </script>
</head>

<body>
<ul class="nav nav-tabs">
    <li><a href="${ctx}/sys/user/list">用户列表</a></li>
    <li class="active">
        <a href="${ctx}/sys/user/form?id=${user.id}">用户
            <shiro:hasPermission name="sys:user:edit">${not empty user.id?'修改':'添加'}</shiro:hasPermission>
            <shiro:lacksPermission name="sys:user:edit">查看</shiro:lacksPermission>
        </a>
    </li>
</ul>
<br/>

<form:form id="inputForm" modelAttribute="reportConfigOut" action="${ctx}/report/configOut/save" method="post" class="form-horizontal">
    <sys:message content="${message}"/>
    <form:hidden path="outResultId"/>
    <form:hidden path="reportId"/>

    <div class="control-group">
        <label class="control-label">表头类型:</label>
        <div class="controls">
            <form:select path="spanType" class="required input-medium">
                <form:option value="0">无合并</form:option>
                <form:option value="1">行合并</form:option>
                <form:option value="2">列合并</form:option>
            </form:select>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>

    <div class="control-group">
        <label class="control-label">合并个数:</label>
        <div class="controls">
            <form:input path="spanValue" htmlEscape="false" maxlength="50" class="required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">表头名称:</label>
        <div class="controls">
            <form:input path="itemName" htmlEscape="false" maxlength="50" class="required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">参数编码:</label>
        <div class="controls">
            <form:input path="itemCode" htmlEscape="false" maxlength="50" class="required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">排序:</label>
        <div class="controls">
            <form:input path="sort" htmlEscape="false" maxlength="50" class="required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">备注:</label>
        <div class="controls">
            <form:textarea path="remark" htmlEscape="false" rows="3" maxlength="200" class="input-xlarge"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>

    <div class="form-actions">
        <shiro:hasPermission name="report:configIn:edit">
            <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
        </shiro:hasPermission>
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
    </div>
</div>
</form:form>
</body>

<script src="${ctxStatic}/jquery-validation/1.11.0/jquery.validate.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function(){
        $("#inputForm").validate({
            submitHandler: function(form){
                loading('正在提交，请稍等...');
                form.submit();
            },
            errorContainer: "#messageBox",
            errorPlacement: function(error, element) {
                $("#messageBox").text("输入有误，请先更正。");
                if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                    error.appendTo(element.parent().parent());
                } else {
                    error.insertAfter(element);
                }
            }
        });
        <%--require初始化--%>
        function initRequire(){
            var val = $('#spanType option:selected').val();
            switch (val){
                case "0":
                    $("#spanValue").closest(".clearfix").hide();
                    $("#itemCode").closest(".clearfix").show();
                    if(!$("#itemCode").hasClass("required")){
                        $("#itemCode").addClass("required");
                    }
                    if($("#spanValue").hasClass("required")){
                        $("#spanValue").removeClass("required");

                    }
                    break;
                case "1":
                    $("#spanValue").closest(".clearfix").show();
                    $("#itemCode").closest(".clearfix").show();
                    if(!$("#itemCode").hasClass("required")){
                        $("#itemCode").addClass("required");
                    }
                    if(!$("#spanValue").hasClass("required")){
                        $("#spanValue").addClass("required");
                    }
                    break;
                case "2":
                    $("#spanValue").closest(".clearfix").show();
                    $("#itemCode").closest(".clearfix").hide();
                    if($("#itemCode").hasClass("required")){
                        $("#itemCode").removeClass("required");
                    }
                    if(!$("#spanValue").hasClass("required")){
                        $("#spanValue").addClass("required");
                    }
                    break;
            }
        }
        initRequire();
        <%--下拉选项--%>
        $("#spanType").on("change",function(){
            initRequire();
        });
    });
</script>
</html>